-
Notifications
You must be signed in to change notification settings - Fork 472
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix DECRBY LLONG_MIN caused an overflow #1581
Conversation
Note that this may break compatibility since in the past doing: `DECRBY key -9223372036854775808` would succeed but create an invalid result. And now we will return an error rejecting the request. Before: ``` 127.0.0.1:6666> set key 0 OK 127.0.0.1:6666> decrby key -9223372036854775807 (integer) 9223372036854775807 127.0.0.1:6666> get key "9223372036854775807" 127.0.0.1:6666> set key 0 OK 127.0.0.1:6666> decrby key -9223372036854775808 (integer) -9223372036854775808 127.0.0.1:6666> get key "-9223372036854775808" ``` After: ``` 127.0.0.1:6666> decrby key -9223372036854775808 (error) ERR decrement would overflow ```
Hi @enjoy-binbin, thanks for taking care of this. Maybe we should fix it in https://github.com/apache/kvrocks/blob/unstable/src/types/redis_string.cc#L320 |
@enjoy-binbin Out of curiosity, do you have a fuzzer to test out Kvrocks? Your recent great fixes seem like a combo rather than random findings :D |
They were actually random findings. |
@git-hulk when doing the -1 * increment_, the overflow is happended, so i can not do the check
|
Haha, cool! |
Got it, thanks |
Thanks all, merging... |
Note that this may break compatibility since in the past doing: `DECRBY key -9223372036854775808` would succeed but create an invalid result. And now we will return an error rejecting the request. Before: ``` 127.0.0.1:6666> set key 0 OK 127.0.0.1:6666> decrby key -9223372036854775807 (integer) 9223372036854775807 127.0.0.1:6666> get key "9223372036854775807" 127.0.0.1:6666> set key 0 OK 127.0.0.1:6666> decrby key -9223372036854775808 (integer) -9223372036854775808 127.0.0.1:6666> get key "-9223372036854775808" ``` After: ``` 127.0.0.1:6666> decrby key -9223372036854775808 (error) ERR decrement would overflow ```
Note that this may break compatibility since in the past doing: `DECRBY key -9223372036854775808` would succeed but create an invalid result. And now we will return an error rejecting the request. Before: ``` 127.0.0.1:6666> set key 0 OK 127.0.0.1:6666> decrby key -9223372036854775807 (integer) 9223372036854775807 127.0.0.1:6666> get key "9223372036854775807" 127.0.0.1:6666> set key 0 OK 127.0.0.1:6666> decrby key -9223372036854775808 (integer) -9223372036854775808 127.0.0.1:6666> get key "-9223372036854775808" ``` After: ``` 127.0.0.1:6666> decrby key -9223372036854775808 (error) ERR decrement would overflow ```
Note that this may break compatibility since in the past
doing:
DECRBY key -9223372036854775808
would succeedbut create an invalid result. And now we will return an
error rejecting the request.
Before:
After: